package com.godme.homework;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Gold {


    static int maxValue = 0;

    public static void collect(List<Integer> mountain, Integer people, int value){
        if(mountain.isEmpty()){
            recordValue(value);
            return;
        }
        int size = mountain.size();
        for(int i=0; i<size;i++){
            Integer currentMountain = mountain.get(i);
            if(currentMountain > people){
                recordValue(value);
                continue;
            }
            collect(mountain.stream().filter(e->!e.equals(currentMountain)).collect(Collectors.toList()), people - currentMountain, value + currentMountain);
        }

    }


    public static void recordValue(int value){
        if(value > maxValue){
            maxValue = value;
        }
    }


    public static void main(String[] args) {
        collect(Arrays.asList(3,4,5,6), 10, 0);
        System.err.println(maxValue);
    }
}
